#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int longestCommonSubsequence(string text1, string text2)
    {
        vector<vector<int>> dp(text1.size() + 1, vector<int>(text2.size() + 1, 0));
        for (int i = 1; i < (int)text1.size() + 1; i++)
        {
            for (int j = 1; j < (int)text2.size() + 1; j++)
            {
                if (text1[i - 1] == text2[j - 1])
                {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
                else
                {
                    dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
                }
            }
        }
        return dp[text1.size()][text2.size()];
    }
};

int main()
{
    string text1{"abcde"};
    string text2{"ace"};
    Solution sol;
    cout << sol.longestCommonSubsequence(text1, text2) << endl;
    return 0;
}